﻿using System.Collections.Generic;

namespace Core.Experiment
{
    public class BlackBoard1
    {
        private class Item
        {
            private object value;
            public void SetValue(object v) => value = v;
            public T GetValue<T>() => (T)value;
        }

        private readonly Dictionary<string, Item> dict = new();

        public void SetValue(string key, object v)
        {
            if (dict.ContainsKey(key) == false)
            {
                dict.Add(key, new Item());
            }
            dict[key].SetValue(v);
        }

        public T GetValue<T>(string key, T defaultValue)
        {
            if (dict.ContainsKey(key) == false)
            {
                return defaultValue;
            }
            return dict[key].GetValue<T>();
        }
    }
}